package org.web.demo.listener;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;

/**
 * @author yexi
 */
@WebListener
@Slf4j
public class CustomServletRequestListener implements ServletRequestListener {
    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        // 监听HttpServletRequest对象的销毁。项目中任何一个Request对象的销毁都会触发该方法的执行
        ServletRequest servletRequest = sre.getServletRequest();
        log.info("request" + servletRequest.hashCode() + "对象销毁了");
    }

    /**
     * 监听 HttpServletRequest 对象的创建并初始化 项目中任何一个 Request 对象的创建并初始化都会触发该方法的执行
     *
     * @param sre
     */
    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        ServletRequest servletRequest = sre.getServletRequest();
        log.info("监听到" + servletRequest + "初始化");
    }
}
